package cn.e4j.modular.api.service;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.api.mapper.FwhfMapper;
import cn.e4j.modular.crm.entity.MmrdT;
import cn.e4j.modular.crm.entity.MmrnT;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FwhfService{
    @Autowired
    FwhfMapper fwhfMapper;

    /**
     * 获取服务单列表
     * mmrd019 1紧急  2一般
     *
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public List<Dto> getServiceOrderListData(Page<Object> page, Dto inDto) {
        return fwhfMapper.getServiceOrderListPage(page,inDto);
    }

    /**
     * 获取评价
     *
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public List<Dto> getStarData(Dto inDto) {

        return fwhfMapper.getStarData(inDto);
    }

    /**
     * 服务回访提交
     *
     * @param
     */
    @Transactional
    public void saveFwhf(List<MmrnT> mmrn_tPos, MmrdT mmrd_tPO) {
        for (MmrnT mmrnT : mmrn_tPos) {
            mmrnT.insert();
        }

        //WHERE  mmrdent = #{mmrdent} AND mmrddocno = #{mmrddocno} AND mmrdseq = #{mmrdseq}
        UpdateWrapper<MmrdT> wrapper = new UpdateWrapper<>();
        wrapper.eq("MMRDENT",mmrd_tPO.getMMRDENT());
        wrapper.eq("MMRDDOCNO",mmrd_tPO.getMMRDDOCNO());
        wrapper.eq("MMRDSEQ",mmrd_tPO.getMMRDSEQ());
        mmrd_tPO.update(wrapper);
    }

}
